//新零售45Trait或与CSRL同Trait 或新零售小trait，csrl45trait BP
//CSRL:BP/AR/TR/SB 新零售开始时间小于等于CSRL零售结束时间E2，
//新零售开始时间S1大于CSRL零售开始时间S2 S2<S1<=E2
//新零售大于CSRL零售

var result_91_1 = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"", "MSG":"","DATA":"","RULE":"FS_91_1"}');
var JSON_LINKSAVE = !isNull(LINKSAVE) ? JSON.parse(LINKSAVE) : [];
var S1 = new Date(NEW_RETAIL_EFF_DATE);
var E1 = new Date(NEW_RETAIL_EXP_DATE);
var JSON_CSRL_LIST = !isNull(CSRL)?JSON.parse(find_Item_inCSRL(ITEM_NBR, CSRL)):[];
var JSON_ITEM_LIST = !isNull(ITEM_LIST) ? JSON.parse(ITEM_LIST) : [];


function inPRICE_TRAIT(PRICE_TRAIT) {
    var arr = ['BP', 'AR', 'TR', 'SB'];
    for (var i = 0; i < arr.length; i++) {
        if (PRICE_TRAIT == arr[i]) {
            return true;
        }
    }
    return false;
}
//判断是否涨价
function RisePrice(TRAIT_STORE_NBR, RETAIL_TYPE, JSON_CSRL_LIST) {
    for (var i = 0; i < JSON_CSRL_LIST.length; i++) {
        var S2 = new Date(JSON_CSRL_LIST[i].EFFECTIVE_DATE);
        var E2 = new Date(JSON_CSRL_LIST[i].EXPIRATION_DATE);
        // 新零售45Trait或与CSRL同Trait 或新零售小trait，csrl45trait
        if ((TRAIT_STORE_NBR == 45 || TRAIT_STORE_NBR == JSON_CSRL_LIST[i].PRICE_TRAIT || TRAIT_STORE_NBR != 45 && JSON_CSRL_LIST[i].PRICE_TRAIT == 45)
            && inPRICE_TRAIT(JSON_CSRL_LIST[i].PRICE_TYPE)
            && RETAIL_TYPE == 'BP'
            && betweenDay(S2, S1) > 0 && betweenDay(S1, E2) >= 0
            && NEW_RETAIL > JSON_CSRL_LIST[i].CUST_BASE_RTL_AMT) {
            return true;
        }
    }
    return false;
}
//新零售如果是BP/SB
//LS开始时间-新零售开始时间<8，新零售开始时间小于LS结束时间
//新零售结束时间小于LS开始时间
//S2-S1<8,S1<E2
function LinkSaveRisePriceBPSB(JSON_LINKSAVE, RETAIL_TYPE,S1,E1) {
    for (var i = 0; i < JSON_LINKSAVE.length; i++) {
        var S2 =  new Date(JSON_LINKSAVE[i].OFFER_BEGIN_DATE);
        var E2 = new Date(JSON_LINKSAVE[i].OFFER_END_DATE);
        if (
            betweenDay(S1, S2) < 8 && betweenDay(S1, E2) > 0
        ) {
            return true;
        }
    }
    return false;
}
if(!isNull(UPC_NBR) && UPC_NBR.toString().substr(0, 2) == '21') {
    if (!isNull(LINKSAVE)
        && !inSuspendBP(ITEM_NBR, NEW_RETAIL_EFF_DATE, JSON_ITEM_LIST, ID, RETAIL_TYPE)
        && RisePrice(TRAIT_STORE_NBR, RETAIL_TYPE, JSON_CSRL_LIST)
        && LinkSaveRisePriceBPSB(JSON_LINKSAVE, RETAIL_TYPE, S1, E1)) {
        result_91_1.CODE = 1;
        result_91_1.ACTION = "APPROVAL_LEVEL";
        result_91_1.LEVEL = "AG";
        result_91_1.MSG = "与Linksave冲突的高风险变价，需GMM审批";
    }
}
JSON.stringify(result_91_1);

